<?php

namespace Shopadmin\Controller;
class LogController extends AdminController
{
    public function cash_list()
    {
        $shop_id = session("shopid");
        $search = I("search", "");
        $where['shop_id'] = $shop_id;
        $where['status'] = 1;//只显示已支付的充值订单
        if (!empty($search)) {
            $where['order_number'] = array('like', "%$search%");
            $where['_logic'] = 'AND';
        }
        $count = M("shop_recharge_order")->where($where)->count();
        $Page = new \Think\Page($count, 10);
        $list = M("shop_recharge_order")->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order("id desc")->select();
        foreach ($list as &$v) {
            $v['paytime'] = timeString($v['paytime']);
            if ($v['pay_type'] == 1) {
                $v['pay_type'] = "支付宝";
            } else {
                $v['pay_type'] = "微信";
            }
        }
        $shop_id=session("shopid");
        $info=M('shop')->where(array('id'=>$shop_id))->find();
        $this->assign("info", $info);
        $this->assign("pages", $Page->show());
        $this->assign("search", $search);
        $this->assign("list", $list);
        $this->display();
    }

    public function delete()
    {
        $id = I("id", "");
        if (M("shop_recharge_order")->where("id=$id")->delete()) {
            $this->ajaxReturn(array("code" => 200, "msg" => "删除成功"));
        } else {
            $this->ajaxReturn(array("code" => 201, "msg" => "删除失败"));
        }
    }

    public function cost_list()
    {
        $shop_id = session("shopid");
        $search = I("search", "");
        $where['shop_id'] = $shop_id;
        if (!empty($search)) {
            $where['order_number'] = array('like', "%$search%");
            $where['_logic'] = 'AND';
        }
        $count = M("wx_transfer")->where($where)->count();
        $Page = new \Think\Page($count, 10);
        $list = M("wx_transfer")->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order("id desc")->select();
        foreach ($list as &$v) {
            $v['money']=$v['money']/100;
            $v['addtime'] = timeString($v['addtime']);
            $weixin=M("wx_user")->where(array('openid'=>$v['openid']))->find();
            $v['weixinimg']=$weixin['headimgurl'];
            $v['nickname']=$weixin['nickname'];
        }
        $shop_id=session("shopid");
        $info=M('shop')->where(array('id'=>$shop_id))->find();
        $this->assign("info", $info);
        $this->assign("pages", $Page->show());
        $this->assign("search", $search);
        $this->assign("list", $list);
        $this->display();
    }
    public function shop_pay(){
        $shop_id=session("shopid");
        $info=M('shop')->where(array('id'=>$shop_id))->find();
        $this->assign("info", $info);
        $this->assign("shop_id", $shop_id);
        $this->display();
    }
}